package com.dingreading.cloud.soms.controller;

import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.common.util.PageUtil;
import com.dingreading.cloud.common.util.aliyun.MstCdnUtil;
import com.dingreading.cloud.soms.service.MstXcxAttendClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/educate/attendClass")
@Api(tags = "名师堂小程序-学生学习课程管理")
public class MstXcxAttendClassController {

    @Resource
    private MstXcxAttendClassService mstXcxAttendClassService;
    @ApiOperation(value = "学生学习轨迹分页列表")
    @PostMapping(value = "/pageListProgress")
    public R<Object> pageList(
            HttpServletRequest request,
            @ApiParam(value = "分页公共类") PageUtil pageUtil,
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "学生姓名/手机号码") @RequestParam(value = "keyword", required = false) String keyword,
            @ApiParam(value = "课节阶段: 1-课前预习, 2-课堂巩固, 3-课后作业, 4-名师精讲") @RequestParam(value = "materialStage", required = false) Integer materialStage,
            @ApiParam(value = "科目uid") @RequestParam(value = "subjectUid", required = false) String subjectUid,
            @ApiParam(value = "学习轨迹开始日期") @RequestParam(value = "beginDate", required = false) String beginDate,
            @ApiParam(value = "学习轨迹结束日期") @RequestParam(value = "endDate", required = false) String endDate
    ) {
        R<Object> r = MstCdnUtil.getIp(request);
        if (R.isError(r))
            return r;
        String ip = (String) r.getData();

        return mstXcxAttendClassService.pageListProgress(
                pageUtil, corpUid, storeUid, staffUid, staffName,
                keyword, materialStage, subjectUid, beginDate, endDate, ip
        );
    }

    @ApiOperation(value = "学生课后作业分页列表")
    @PostMapping(value = "/pageListHomework")
    public R<Object> pageListHomework(
            HttpServletRequest request,
            @ApiParam(value = "分页公共类") PageUtil pageUtil,
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "学生姓名/手机号码") @RequestParam(value = "keyword", required = false) String keyword,
            @ApiParam(value = "科目uid") @RequestParam(value = "subjectUid", required = false) String subjectUid,
            @ApiParam(value = "开始日期") @RequestParam(value = "beginDate", required = false) String beginDate,
            @ApiParam(value = "结束日期") @RequestParam(value = "endDate", required = false) String endDate
    ) {
        R<Object> r = MstCdnUtil.getIp(request);
        if (R.isError(r))
            return r;
        String ip = (String) r.getData();

        return mstXcxAttendClassService.pageListHomework(
                pageUtil, corpUid, storeUid, staffUid, staffName,
                keyword, subjectUid, beginDate, endDate, ip
        );
    }

    @ApiOperation(value = "获取当前课后作业")
    @PostMapping(value = "/getBean", produces = "application/json; charset=UTF-8")
    public R<Object> getBean(
            HttpServletRequest request,
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "作业uid") @RequestParam(value = "uid") String uid
    ) {
        R<Object> r = MstCdnUtil.getIp(request);
        if (R.isError(r))
            return r;
        String ip = (String) r.getData();

        return mstXcxAttendClassService.getBean(corpUid, storeUid, staffUid, staffName, uid, ip);
    }

    @ApiOperation(value = "教师批改作业")
    @PostMapping(value = "/correct", produces = "application/json; charset=UTF-8")
    public R<Object> correct(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "作业uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "作业是否通过 2-批改通过, -1-批改不通过") @RequestParam(value = "status") Integer status,
            @ApiParam(value = "老师给学生评分") @RequestParam(value = "teacherScore") Integer teacherScore,
            @ApiParam(value = "老师给学生评价") @RequestParam(value = "evaluationText", required = false) String evaluationText

    ) {
        return mstXcxAttendClassService.correct(
                corpUid, storeUid, staffUid, staffName, uid,
                status, teacherScore, evaluationText
        );
    }

}
